package com.wang.controller;

import com.wang.auto.addSet.AddSetAutoSend;
import com.wang.auto.addSet.AddSetControlUtil;
import com.wang.conf.AppData;
import com.wang.packpojo.AddSetMsg;
import com.wang.packpojo.Param;
import com.wang.pojo.*;
import com.wang.service.*;
import com.wang.util.*;
import com.wang.webSocket.WebSocketUtil;

import java.text.ParseException;
import java.util.*;

public class BetDemo {
    private Object object;


    public BetDemo(Object object) {
        this.object = object;
    }


    public void notice() {
        object.notify();
    }

    public static void main(String[] args) {


        List<Param> paramList = new ArrayList<>();
        Param param1 = new Param();
        param1.setParamValue("5.88");
        param1.setParamName("雨水总磷");
        paramList.add(param1);


            if(!(paramList.size() >0)){
                return;
            }

                    List<String> wuranyuanNameList = new ArrayList<>();
                    //集合转成map
                    Map<String,Param> paramMap = new HashMap<>();
                    for(Param param : paramList){

                        //查询最新的一条数据
                        if(param.getParamName().contains("COD")){
                            wuranyuanNameList.add(param.getParamName());
                            paramMap.put(param.getParamName(),param);
                        }
                        if(param.getParamName().contains("氨氮")){
                            wuranyuanNameList.add(param.getParamName());
                            paramMap.put(param.getParamName(),param);
                        }
                        if(param.getParamName().contains("总磷")){
                            wuranyuanNameList.add(param.getParamName());
                            paramMap.put(param.getParamName(),param);
                        }
                    }

                    //是否移除污染源标识
                    Integer wuranyuanFlag = 0;

                    //判断与上一条数据是否相等

                    CheckData checkData =  new CheckData();
                    checkData.setCheckDataName("雨水总磷");
                    checkData.setCheckDataValue("5.88");
                    for(String wuranyuanName : wuranyuanNameList){

                        if(paramMap.containsKey(wuranyuanName)){
                            if(paramMap.get(wuranyuanName).getParamValue().equals(checkData.getCheckDataValue())){
                                wuranyuanFlag = 1;
                            }
                        }
                    }


                    if(wuranyuanFlag == 1) {

                        //存储日志

                        //存储日志
                        DevLog devLog = new DevLog();
                        devLog.setDevId("1");
                        devLog.setDevLogTypeCode(AppData.devRunLogCode);
                        devLog.setDevEventTypeCode("0142");
                        StringBuilder sb = new StringBuilder();
                        for(Map.Entry<String,Param> entry : paramMap.entrySet()){
                            Param param = entry.getValue();
                            sb.append(param.getParamName()+":"+param.getParamValue());
                        }
                        String msg = "数据重复："+ DateUtil.getStrDate()+":"+sb.toString();
                        devLog.setDevLogContent(msg);
                        devLog.setCreateTime(DateUtil.getStrDate());
                        devLog.setOperateUser("system");
                        devLog.setIsRead(1);
                        //存储



                        //去除污染源数据
                        for (String ss : wuranyuanNameList) {
                            paramList.removeIf(param -> param.getParamName().equals(ss));
                        }
                    }

        System.out.println(paramList.size());

        if(paramList.size()==0){
            System.out.println("test");
            return;
        }
    }
}
